package com.selfstudy.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.selfstudy.common.annotation.Log;
import com.selfstudy.common.core.controller.BaseController;
import com.selfstudy.common.core.domain.AjaxResult;
import com.selfstudy.common.enums.BusinessType;
import com.selfstudy.system.domain.SRoom;
import com.selfstudy.system.service.ISRoomService;
import com.selfstudy.common.utils.poi.ExcelUtil;
import com.selfstudy.common.core.page.TableDataInfo;

/**
 * 自习室Controller
 * 
 * @author lgf
 * @date 2024-01-29
 */
@Api("自习室")
@RestController
@RequestMapping("/system/room")
public class SRoomController extends BaseController
{
    @Autowired
    private ISRoomService sRoomService;

    /**
     * 查询自习室列表
     */
    @ApiOperation("自习室查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "floorId", value = "教学楼id", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "startDate", value = "预约开始时间", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "endDate", value = "预约结束时间", dataType = "String", dataTypeClass = String.class),
    })
    @PreAuthorize("@ss.hasPermi('system:room:list')")
    @GetMapping("/list")
    public TableDataInfo list(SRoom sRoom)
    {
        startPage();
        List<SRoom> list = sRoomService.selectSRoomList(sRoom);
        return getDataTable(list);
    }

    /**
     * 导出自习室列表
     */
    @PreAuthorize("@ss.hasPermi('system:room:export')")
    @Log(title = "自习室", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SRoom sRoom)
    {
        List<SRoom> list = sRoomService.selectSRoomList(sRoom);
        ExcelUtil<SRoom> util = new ExcelUtil<SRoom>(SRoom.class);
        util.exportExcel(response, list, "自习室数据");
    }

    /**
     * 获取自习室详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:room:query')")
    @GetMapping(value = "/{roomId}")
    public AjaxResult getInfo(@PathVariable("roomId") Long roomId)
    {
        return success(sRoomService.selectSRoomByRoomId(roomId));
    }

    /**
     * 新增自习室
     */
    @PreAuthorize("@ss.hasPermi('system:room:add')")
    @Log(title = "自习室", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SRoom sRoom)
    {
        return toAjax(sRoomService.insertSRoom(sRoom));
    }

    /**
     * 修改自习室
     */
    @PreAuthorize("@ss.hasPermi('system:room:edit')")
    @Log(title = "自习室", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SRoom sRoom)
    {
        return toAjax(sRoomService.updateSRoom(sRoom));
    }

    /**
     * 修改自习室coordinateJson 根据roomId
     */
    @ApiOperation("配置自习室坐标--pc端专用")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "roomId", value = "自习室id", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "coordinateJson", value = "坐标json", dataType = "String", dataTypeClass = String.class),
    })
    @Log(title = "自习室", businessType = BusinessType.UPDATE)
    @PostMapping("/edit/coordinateJson")
    public AjaxResult editCoordinateJson(@RequestBody SRoom sRoom)
    {
        return toAjax(sRoomService.updateSRoom(sRoom));
    }


    /**
     * 删除自习室
     */
    @PreAuthorize("@ss.hasPermi('system:room:remove')")
    @Log(title = "自习室", businessType = BusinessType.DELETE)
	@DeleteMapping("/{roomIds}")
    public AjaxResult remove(@PathVariable Long[] roomIds)
    {
        return toAjax(sRoomService.deleteSRoomByRoomIds(roomIds));
    }
}
